package com.cmy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller()
@RequestMapping("/user")
public class LoginController {

    @RequestMapping("/main")
    public String main(HttpSession session,Model model){
        String name = (String) session.getAttribute("userLogInfo");
        model.addAttribute("username",name);
        return "main";
    }

    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/login")
    public String login(HttpSession session, String username, String password){
        //将用户信息存入session
        session.setAttribute("userLogInfo",username);
        return "redirect:/user/main";
    }
    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.removeAttribute("userLogInfo");
        return "redirect:/index.jsp";
    }

}

    